#encoding=utf8
import os
import traceback
import sys
reload(sys)
sys.setdefaultencoding("utf-8")
Useage='''Useage like following:
python get_dev_patch_list.py --site "upgradeSite" --proxyConf "" --devType "" --versionList ""
    --site:       the upgrade site, eg: http://update.epic.com/update/
	--proxyConf   the proxy config, eg:{"pswd": "pswd", "user": "user","server": "1.1.1.1","port":806}
	--devType     the device's type, eg:IPS
	--versionList the device's all version info, eg: 
    [
        {"vtype":"firmwire","version":"5.6.9.31"},
        {"vtype":"agent","version":"5.6.9.63"},
        {"vtype":"sysrule","version":"5.6.9.12581"},
        {"vtype":"ulrlib","version":"5.6.0.130"},
        {"vtype":"avrule","version":"5.6.9.12542"}
    ]
	return: if call failed return the [], else return the device's patchList, eg:
	[
        {
            "devType":"RSAS",
            "patchType":"vulsys",
            "name":"rsas-sysvul-version1.0.bin",
            "version":"1.0.0.1",
            "size":125684,
            "md5":"jhfkansdfkemnfkwefnk",
            "date":"2015-02-25 12:22:00",
            "download":http://update.epic.com/update/downloads/id/11505,
            "explainEn":"it’s for update",
            "explainZh":"本次更新主要包含"
        },
        {
            …
        }
    ]

'''
#demo
def main():
    try:
        patchList="[{\"devType\":\"IPS\",\"patchType\":\"agent\",\"name\":\"eoi.agentpatch.5.6.9.65.bin\",\"version\":\"5.6.9.65\",\"size\":60509961,\"md5\":\"1900628bf5beceff4e1b3fc70c6d84f8\",\"date\":1436182291825,\"explainEn\":\"update for ...\",\"explainZh\":\"本次更新目的为...\",\"download\":\"http://update.epic.com/update/downloads/id/11508\"},{\"devType\":\"IPS\",\"patchType\":\"av\",\"name\":\"eoi.unify.avrulepatch.ips.5.6.9.25094.av\",\"version\":\"5.6.9.25094\",\"size\":52178160,\"md5\":\"61f83c4616aaf91f3d94e30f126f7b1d\",\"date\":1436182291825,\"explainEn\":\"update for ...\",\"explainZh\":\"本次更新目的为...\",\"download\":\"http://update.epic.com/update/downloads/id/11509\"}]"
        print patchList
        return patchList
    except BaseException, e:
        return str(traceback.format_exc())

if __name__ == '__main__':
    main()
